home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / yacas_alg / yacas_morphos / share / yacas / include / lisphash.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  2.6 KB  |  88 lines

  1. /** \file lisphash.h
  2.  *  hashing of strings. Each string will exist only once in the
  3.  * hash table, and have an unique id.
  4.  */
  5.  
  6.  
  7. #ifndef __lisphash_h__
  8. #define __lisphash_h__
  9.  
  10. #include "yacasbase.h"
  11. #include "grower.h"
  12. #include "lispstring.h"
  13.  
  14.  
  15. const LispInt KSymTableSize = 211;
  16. LispInt  LispHash( char *s );
  17. LispInt  LispHashCounted( char *s,LispInt length );
  18. LispInt  LispHashStringify( char *s );
  19. LispInt  LispHashUnStringify( char *s );
  20. LispInt LispHashPtr(LispStringPtr aString);
  21.  
  22. /**
  23.  * This is the symbol table, implemented as a hash table for fast
  24.  * lookup. It is meant to store any string just once, have fast
  25.  * searching for strings and return a reference to the string.
  26.  * This also allows fast comparison of two strings (two strings
  27.  * are equal iff the pointers to the strings are equal).
  28.  */
  29. class LispHashTable : public YacasBase
  30. {
  31. public:
  32.     ~LispHashTable();
  33.     // If string not yet in table, insert. Afterwards return the string.
  34.     LispStringPtr LookUp(LispCharPtr aString,
  35.                          LispBoolean aStringOwnedExternally=LispFalse);
  36.     /// LookUp that takes ownership of the string
  37.     LispStringPtr LookUp(LispStringPtr aString);
  38.     LispStringPtr LookUpCounted(LispCharPtr aString,LispInt aLength);
  39.     LispStringPtr LookUpStringify(LispCharPtr aString,
  40.                          LispBoolean aStringOwnedExternally=LispFalse);
  41.     LispStringPtr LookUpUnStringify(LispCharPtr aString,
  42.                          LispBoolean aStringOwnedExternally=LispFalse);
  43.  
  44.     // GarbageCollect
  45.     void GarbageCollect();
  46. private:
  47.     CDeletingArrayGrower<LispStringPtr> iHashTable[KSymTableSize];
  48. };
  49.  
  50.  
  51.  
  52. /** VoidGrow is a helper class for LispAssociatedHash
  53.  */
  54. class VoidGrow : public CArrayGrower<void*>
  55. {
  56. };
  57.  
  58. /** LispAssociatedHash allows you to associate arbitrary
  59.  * information with a string in the above hash table. You can
  60.  * specify what type of information to link to the string, and
  61.  * this class then stores that information for a string. It is
  62.  * in a sense a way to extend the string object without modifying
  63.  * the string class itself. This class does not own the strings it
  64.  * points to, but instead relies on the fact that the strings
  65.  * are maintained in a hash table (like LispHashTable above).
  66.  */
  67. template<class T>
  68. class LispAssociatedHash : public YacasBase
  69. {
  70. public:
  71.     inline ~LispAssociatedHash();
  72.     inline T* LookUp(LispStringPtr aString);
  73.     inline void SetAssociation(const T& aData, LispStringPtr aString);
  74.     inline void Release(LispStringPtr aString);
  75.  
  76. private:
  77.     // The next array is in fact an array of arrays of type LAssoc<T>
  78.     VoidGrow iHashTable[KSymTableSize];
  79.     
  80. };
  81.  
  82.  
  83.  
  84. #include "lisphash.inl"
  85.  
  86.  
  87. #endif
  88.